1. The Field of the Invention
The invention generally relates to managing cached content. More specifically, the invention relates to extending cache dependency classes such that developers can create custom cache dependencies.
2. Background and Relevant Art
In modern computer systems and network systems, data caching is an effective tool to speed-up the delivery of data to those who request it. Generally, data caching involves storing frequently requested data at a location where the data can be quickly retrieved. In one example, data stored in physical memory of a computer system can be retrieved quicker than data stored on a hard drive in the computer system. This is in part due to hard drives typically having greater data retrieval latencies as compared to physical memory. Likewise, data stored on a hard drive or in memory on a server computer system can be accessed more efficiently than data stored at a remote database. Further, the use of cached data can reduce the number of calculations needed to generate content for delivery to a requesting client computer system.
Modem networks have facilitated the ability to broadly transfer digital information to and from various locations. One way of making data available for transport is by creating a static file such as an HTML file that can be downloaded from the server to a client computer system where it can be viewed. Static files can be cached in a variety of locations including at a server computer system, in a regional database, or even locally on the client computer system. When computer system static files are stored at a client computer system, retrieval and display by the client computer system is, for all practical purposes, instantaneous. Even when static files are stored directly on a server computer system connected to the client computer system (commonly known as output caching), retrieval of cached content can occur relatively quickly. Further, because of their static nature, static files can be cached for long periods of time, essentially indefinitely.
Unfortunately, static files cannot include real-time or custom content. Often, it is desirable to present content that changes on a periodic basis or that is formed from a calculation or manipulation of other content. While such content can still be cached, the cached values of the content are valid only for a limited duration. As such, the cache must be refreshed to ensure that the data is valid.
One technology that has assisted Web developers in creating Web pages and Websites is the use of scripts or modular pieces of computer executable code that are run on a Web page server such as, for example, an Internet Information Server. Scripts can be embedded among other HTML tags to create Web pages that are dynamic and customizable. Just as objects can be called in programs such as those written in Visual Basic, JavaScript, and C#, so to can the same objects be called in scripts that are based on these and other languages.
A class is an object within a programming framework such as the ASP.NET framework. The ASP.NET framework comprises thousands of classes that Web page developers can use to develop Web pages. In a manner similar to accessing a file through a directory path, classes can be accessed by reference to a particular name space. For example, a reference to the name space System.WinForms.Form provides an indication of the location of a particular class. Classes can be associated with properties, events and methods. A property can be thought of as some variable assignment or a setting in a corresponding class (e.g., x=5). An event is a flag that is raised upon the occurrence of an event. The event can be read by other classes or other applications to cause some action to be taken. A method provides a way to invoke the functionality of a corresponding class to perform an action (e.g. output data to a display device). A method defines how functionality is offered to external components.
To facilitate the caching of content and hence improve performance of a Web page server, a programming framework can include classes for retrieving data from various locations such as for example, files, databases and Web services, and classes for manipulating data through various operations. In some environments, a Web page server computer system with access to these classes (e.g., an ASP server) may create and store HTML code based on real time content, which is to be sent to the client computer system in an output caching scenario. In other environments, a Web page server computer system may cache content, such as an XML file, locally at the Web page server computer system so that the content does not need to be retrieved or recalculated each time a Web page that is to include the content is requested.
Some programming frameworks allow Web developers to create instructions that, when executed, cause content to be stored in cache. For example, to insert an entry into cache, the following instruction can be executed: Cache.Insert([key], [value], [dependency]) where key is reference identifier for the cache entry, value is the value (or content) placed into the cache entry, and dependency is an optional argument that defines when the value for the key should be purged from the cache. Dependency is an instance of a class, for example a CacheDependency class, that can be used to cause the cache value to be dependent on the occurrence of a particular event.
Some programming frameworks support cache dependencies that cause a cached value to be dependent on either a time, a file or a key. A time cache dependency causes an entry associated with the specific dependency to be purged after the expiration of a specific period of time. For example, the Cache.Insert instruction can be implemented as follows to cause data to be dependent on time:
Cache.Insert(strCacheKey, dataset, nothing, DateTime.Now.AddMinutes(60), TimeSpan.Zero, CacheItemPriority.High),
More specifically, the DateTime.Now.AddMinutes(60) instruction causes an entry in the cache to be purged from the cache after 60 minutes. Using a time cache dependency that is set too short can result in the too frequent purging of the cache and the added cost of frequently fetching data from a database or the cost of calculating data to be stored in the cache. If the time value is set to long, there is the risk that the data stored in the cache will be invalid when it is delivered to a requesting client computer system.
The Cache.Insert instruction can also be used to implement a file cache dependency that causes a cache entry to be purged if there is a change in a particular file. Further, the Cache.Insert instruction can be used to implement a key dependency that causes one or more cache entries to be purged when some other cache value stored in memory changes. Using a key dependency, the changing of one cache value can cause a number of dependent cache values to be purged from the cache.
While the three cache dependencies described above: time, file and key, are useful for keeping values stored in cache fresh, the classes that implement these dependencies are typically sealed. Thus, Web developers typically have no way to cause cache entries to be dependent on other types of events. This prevents various other types of cache dependencies, which may make the management of the cache more efficient, from being used. Accordingly, what would be advantageous are mechanisms for extending the types of dependencies the can be used to invalidate cache entries.